{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "[[1,0,100],[0,1,200]] \n",
    "将其拆分为2*2 和 2*1的矩阵\n",
    "matA [[1,0],[0,1]] \n",
    "matB [[100],[200]]\n",
    "matC 为输入矩阵即[x,y]\n",
    "运算过程：A*C+B=[[1*x+0*y],[0*x+1*y]]+[[100],[200]]=[[x+100],[y+200]]\n",
    "(10,20)->(110,120)\n",
    "'''\n",
    "import cv2\n",
    "import numpy as np\n",
    "\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "cv2.imshow('src',img)\n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "\n",
    "# 移位矩阵 2*3\n",
    "matShift = np.float32([[1,0,100],[0,1,200]])\n",
    "# 调用API：参数1：原始图片信息 参数2：移位矩阵 参数3：图片的宽高信息\n",
    "dstImg = cv2.warpAffine(img,matShift,(width,height))\n",
    "cv2.imshow('dstImg',dstImg)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 自己编码实现算法\n",
    "dstImg2 = np.zeros(img.shape,np.uint8)\n",
    "for i in range(0,height):\n",
    "    for j in range(0,width-100):\n",
    "        dstImg2[i,j+100] = img[i,j]\n",
    "cv2.imshow('dstImg2',dstImg2)      \n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
